package com.ruoyi.netty.handler;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.netty.Command;
import com.ruoyi.netty.NettyServer;
import com.ruoyi.netty.Result;
import io.netty.channel.ChannelHandlerContext;

/**
 * @author Zoo
 */
public class ConnectionHandler {

    public static void execute(ChannelHandlerContext ctx, Command command){

        NettyServer.USERS.put(command.getNickname(),ctx.channel());

        ctx.channel().writeAndFlush(Result.success("与服务器建立连接成功"));
        ctx.channel().writeAndFlush(Result.success(JSON.toJSONString(NettyServer.USERS.keySet())));
    }
}
